home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / im2gif / clip.c next >
Text File  |  1991-11-24  |  2KB  |  101 lines

  1. /* Clip rows and columes, assume 612 columes
  2.  
  3. clip rows columes
  4.  
  5.     rows = number of rows to skip from top of image
  6.     columes  = nummber of pixels to skip from left side
  7.  
  8. NK6K
  9.  
  10. */
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include <fcntl.h>
  14. #include <sys\types.h>
  15. #include <sys\stat.h>
  16.  
  17. #define LINE_SIZE 612
  18. #define NUM_LINE_FIELD 288
  19.  
  20.  
  21. long start_field_2;
  22. int lines=0;
  23. int skip_lines=0;
  24. int skip_cols = 0;
  25.  
  26. char buff[LINE_SIZE];
  27. int fillval=0;
  28. int line_size;
  29.  
  30. main(argc,argv)
  31. int argc;
  32. char *argv[];
  33. {
  34.  
  35.     int fi1,fi2,fo;
  36.     int i,insize;
  37.  
  38.  
  39.  
  40.     if (argc<2) {
  41.         printf ("usage: clip in out row col\n");
  42.         printf ("row - number of lines from top to remove\n");
  43.         printf ("col - number of columes from left to remove\n");
  44.         exit(1);
  45.     }
  46.  
  47.  
  48.     skip_lines = atoi(argv[3]);
  49.     skip_cols = atoi(argv[4]);
  50.  
  51.     if (argc>5) line_size = atoi(argv[5]);
  52.     else line_size = LINE_SIZE;
  53.  
  54.     if ((fi1= open(argv[1], O_BINARY)) == -1){
  55.         printf("cannot open: %s\n",argv[1]);
  56.         perror("On input file");
  57.         exit(1);
  58.     }
  59.  
  60.     if ((fo = open(argv[2], 0)) != -1){
  61.         printf("output file exists.  Aborted\n");
  62.         exit(1);
  63.     }
  64.  
  65.     if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
  66.         printf("cannot open: %s\n",argv[2]);
  67.         perror("On output file");
  68.         exit(1);
  69.     }
  70.  
  71.     
  72.     buff[LINE_SIZE]=0;
  73.     while (1) {
  74.  
  75.         if (read(fi1, buff, line_size)<line_size) {
  76.             break;
  77.         }
  78.  
  79.         if (lines >= skip_lines) {
  80.             if (skip_cols>0) {
  81.                 if (write(fo,buff+skip_cols,line_size-skip_cols)==-1) {
  82.                     perror("On output file 1st field\n");
  83.                     exit(1);
  84.                 }
  85.                }
  86.             else if (write(fo,buff,line_size+skip_cols)==-1) {
  87.                 perror("On output file 1st field\n");
  88.                 exit(1);
  89.              }
  90.         }
  91.     
  92.  
  93.         lines++;
  94.     }
  95.     close (fo);
  96.     close (fi1);
  97.  
  98. }
  99.  
  100.  
  101.